﻿using UnityEngine;

namespace AudioStudio
{
    /// <summary>
    /// 全局的声音对象
    ///   内部使用，不可手动添加
    /// </summary>
    public class GlobalSoundObj : MonoBehaviour
    {
        void Awake()
        {
            AkSoundEngine.RegisterGameObj(gameObject, "Global SoundObject");
            AkSoundEngine.Log("Register: Global SoundObject");

            ListenerManager.SetListener(gameObject);

            DontDestroyOnLoad(gameObject);
        }

        void Destroy()
        {
            if (AkSoundEngine.IsInitialized())
            {
                ListenerManager.RemoveListener(gameObject);
                AkSoundEngine.UnregisterGameObj(gameObject);
                AkSoundEngine.Log("Unregister: Global SoundObject");
            }
        }

        void Update()
        {
            ListenerManager.Refresh();
        }
    }
}
